1 /*
2 * EditNodeView
3 *
4 * $RCSfile: EditNodeView.java,v $
5 * $Revision: 1.4 $
6 * $Date: 2004/01/10 20:10:46 $
7 * $Source: /cvsroot/jpui/jpui/src/EditNodeView.java,v $
8 *
9 * JPUI - Java Preferences User Interface
10 * Copyright (C) 2003
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 2 of the License, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20 * more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
24 * Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Author: macksold@users.sourceforge.net
27 */
28
29 import java.awt.BorderLayout;
30 import java.awt.Color;
31 import java.util.Observable;
32 import java.util.Observer;
33 import java.util.prefs.Preferences;
34
35 import javax.swing.JOptionPane;
36 import javax.swing.JPanel;
37 import javax.swing.JTable;
38
39 /***
40 * Right hand side of UI. Responsible for rendering
41 * the current preference node.
42 */
43 public class EditNodeView implements Observer {
44 private JPanel moPanel;
45 private JTable moTable;
46
47 /***
48 * ctor
49 */
50 public EditNodeView() {
51 moPanel = new JPanel();
52 moPanel.setLayout(new BorderLayout());
53 moTable = new JTable();
54
55 PreferencesModel.Instance().addObserver(this);
56 renderTable();
57 }
58
59 /***
60 * @return javax.swing.JPanel
61 */
62 public JPanel getPanel() {
63 return moPanel;
64 }
65
66 /***
67 * Retrieves the current node from the model and
68 * renders it via a JTable.
69 */
70 private void renderTable() {
71 Preferences oPref = PreferencesModel.Instance().getCurrentNode();
72
73 moPanel.remove(moTable.getTableHeader());
74 moPanel.remove(moTable);
75 moTable = new JTable(new PreferencesNodeTable(oPref));
76 moTable.setShowGrid(true);
77 moTable.setGridColor(Color.LIGHT_GRAY);
78 moPanel.add(moTable.getTableHeader(), BorderLayout.NORTH);
79 moPanel.add(moTable, BorderLayout.CENTER);
80 moPanel.validate();
81 }
82
83 /***
84 * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
85 */
86 public void update(Observable oObject, Object oArg) {
87 renderTable();
88 }
89
90 /***
91 * Prompts for and creates a new attribute key for the
92 * currently selected node.
93 */
94 public void newKey() {
95 String sNewKey =
96 JOptionPane.showInputDialog(
97 moPanel.getParent(),
98 Resources.getString("new_attr_message"),
99 Resources.getString("new_attr_title"),
100 JOptionPane.QUESTION_MESSAGE);
101 if (sNewKey != null) {
102 PreferencesModel.Instance().setAttribute(sNewKey, "");
103 }
104 }
105
106 /***
107 * Deletes the currently selected attribute.
108 */
109 public void deleteKey() {
110 int nRow = moTable.getSelectedRow();
111 if(nRow >= 0) {
112 String sKey = moTable.getValueAt(nRow, 0).toString();
113 if (sKey != null) {
114 PreferencesModel.Instance().removeAttribute(sKey);
115 }
116 }
117 }
118 }
This page was automatically generated by Maven